package com.game.World.Logical;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class DoorChecker {
	
	
	 private List<Coordinate> list;
	 
	 private int temp;
	 private int count;
	 
	 public DoorChecker() {
		 list = new ArrayList<Coordinate>();
		 temp = 0;
		 count = 0;
	 }
	 
	 public DoorChecker(Room room) { 
		 list = new ArrayList<Coordinate>();
		 setDoors(room);
	 }
	 
	 
	 public void setDoors(Room room) { 
		 list.clear();
		 for(int j = 0; j<room.getHeight(); j++)
			 for (int i = 0; i<room.getWidth(); i++	)
			 {
				 if (room.instance[i][j]=='d')
				 {
					 Coordinate c = new Coordinate();
					 c.x = i;   
					 c.y = j;
					 list.add(c);
				 }
			 }
		 Random rand = new Random();
		 if (list.size()>0)
			 temp = rand.nextInt(list.size());
		 else
			 temp = 0;
		 count = 0;
	 }
	 
	 public boolean isDoorNext() {
		 if (count<list.size())
			 return true; 
		 	else
		 		return false;
	 }
	 
	 public Coordinate getNextCoord() {
		count++;
		if (temp==list.size())
			temp = 0;
		 return list.get(temp++);
		 
	 }
	 
	 public void reset() {
		 Random rand = new Random();
		 if (list.size()>0)
			 temp = rand.nextInt(list.size());
		 else 
			 temp = 0;
		 count = 0;
	 }
	 
	 
	 public void clearDoors() {
		 temp = 0;
		 count = 0;
		 list.clear();
	 }
	 
	 
	 
}
